Constructor: | |
---|---|
Entry( master , **options . . ) |
Where o master: indicates the parent window. o Options: additional parameters. |
Options | |
---|---|
textvariable | A variable associated with Text-Box. |
bg / fg | Background / Foreground color. |
cursor | cursor (arrow, dot,cross etc.). |
font | The font used for the text |
justify |
text alignment can be CENTER, LEFT, or RIGHT. For ex: justify=CENTER |
relief | It can be SUNKEN, RAISED, GROOVE, RIDGE etc. |
show |
Indicates the password char . For ex: show="*" |
state | NORMAL/DISABLED. The default is state=NORMAL. |
width | Width of textbox in chars |
Methods | |
---|---|
get() |
|
insert ( index, data ) | Inserts data at specified index. |
delete ( first, last=None ) |
|
config( **options ) |
|
from tkinter import * def showdata(): data=t1.get() print(data) win=Tk() win.geometry("500x300") t1=Entry(win) t1.pack() b1=Button(win,text="Show",command=showdata) b1.pack() win.mainloop()
from tkinter import * def checkpwd(): data=t1.get() if data=="admin": print("Valid User") else: print("InValid User") win=Tk() win.geometry("300x200") t1=Entry(win,show="*",justify=CENTER) t1.pack() b1=Button(win,text="Check",command=checkpwd) b1.pack() win.mainloop()
from tkinter import * class MyFrame(Tk): def __init__(self): super().__init__() self.geometry("200x300") self.configure(bg="yellow") win=MyFrame() win.mainloop()
from tkinter import * class MyWin(Tk): def __init__(self): super().__init__() self.geometry("300x200") self.txt=Entry(self,show="*",justify=CENTER) self.txt.pack() self.btn=Button(self,text="Check",command= self.checkpwd) self.btn.pack() def checkpwd(self): pwd=self.txt.get() if pwd=="admin": print("Valid User") else: print("Invalid User") self.txt.delete(0,last=END) win=MyWin() win.mainloop()
from tkinter import * class MyWin(Tk): def __init__(self): super().__init__() self.geometry("300x200") self.t1=Entry(self) self.t1.pack() self.btn=Button(self,text="Exchange",command=self.exg) self.btn.pack() self.t2=Entry(self) self.t2.pack() def exg(self): s1=self.t1.get() s2=self.t2.get() self.t1.delete(0,END) self.t2.delete(0,END) self.t1.insert(0,s2) self.t2.insert(0,s1) win=MyWin() win.mainloop()